﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ModelLayer;
using System.Data;
using System.Windows.Forms;

namespace BusinessLayer
{
    public static class DesligadosActions
    {



        public static void ListaObrasDesligadas(ref RichTextBox rt, ObraDesligada.ObraDataTable obra, ObraDesligada.ObraContemDataTable obraCont,
           ObraDesligada.ReservaDataTable resr, ObraDesligada.OficinaDataTable oficina)
        {

            object obraId = null;
            foreach (DataRow r in obra.Rows)
            {
                if (r.ItemArray[0] != null)
                {
                    obraId = r.ItemArray[0]; /*Faço esta afectação logo por saber que o id de obra vem logo na primeira posição do array*/
                }
                foreach (object o in r.ItemArray)
                {
                    if (o != null)
                    {
                        rt.AppendText(o.ToString() + "  ");
                    }

                }
                rt.AppendText("\n");
                fillActosPorObra(ref rt, obraId, obraCont);
                fillPeçasPorObra(ref rt, obraId, resr);

            }
        }

        private static void fillActosPorObra(ref RichTextBox rt, object o, ObraDesligada.ObraContemDataTable obraCont)
        {

            foreach (DataRow r in obraCont.Rows)
            {
                if (r.ItemArray[0] != null)
                {
                    if (r.ItemArray[0].ToString().Equals(o.ToString()))
                    {
                        foreach (object oAct in r.ItemArray)
                        {
                            if (oAct != null)
                            {
                                rt.AppendText(oAct.ToString() + "  ");
                            }

                        }
                    }
                }
                rt.AppendText("\n");
            }
        }
        private static void fillPeçasPorObra(ref RichTextBox rt, object o, ObraDesligada.ReservaDataTable resr)
        {
            foreach (DataRow r in resr.Rows)
            {
                if (r.ItemArray[0] != null)
                {
                    if (r.ItemArray[0].ToString().Equals(o.ToString()))
                    {
                        foreach (object oPec in r.ItemArray)
                        {
                            if (oPec != null)
                            {
                                rt.AppendText(oPec.ToString() + "  ");
                            }

                        }
                    }
                }
                rt.AppendText("\n");
            }
        }
    }
}
